Skip to content

Support dynamic/composite internal helper args (#1889)#2016

Open
Th0rgal wants to merge 4 commits into
mainfrom
task/1889-internal-helper-args
Open

Support dynamic/composite internal helper args (#1889)#2016
Th0rgal wants to merge 4 commits into
mainfrom
task/1889-internal-helper-args

Conversation

@Th0rgal

@Th0rgal Th0rgal commented Jun 12, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds shared internal argument expansion helpers (Compiler/CompilationModel/InternalArgs.lean): internal helper definitions now receive expanded Yul slots for dynamic/composite params, and helper calls forward source-level dynamic/composite args by direct param/local reference with slot expansion.
  • Updates IR-generation supported-fragment proofs for the new internal helper table threading and the Yul call-closure proof for internal calls; long proofs split to satisfy the 50-line limit.
  • PrintAxioms.lean regenerated (zero new axioms, no sorry, no native_decide).

Closes #1889. Tier 1 dynamic ABI codec track (downstream: Morpho Midnight ECM removal). Stacked on #2006 (#1975 struct-array calldata).

Test plan

  • lake build Verity Contracts Compiler PrintAxioms → "Build completed successfully."
  • refresh_verification_artifacts.sh[refresh] PASS
  • make check → "All checks passed."
  • scripts/check_proof_length.py passed
  • CI green

Note

Medium Risk
Changes sit on the core statement/expression lowering path and alter generated Yul for internal calls with dynamic ABI shapes; mistakes would miscompile contracts rather than fail at compile time, though validation and regression tests narrow the surface.

Overview
Internal helper argument lowering is reworked so calls with arrays, bytes, static tuples, and ADTs match the callee’s expanded Yul signature instead of passing a single scalar per source argument.

A new InternalArgs module centralizes Yul parameter naming (internalFunctionYulParamNames, forwarding slot names) and moves related helpers out of Dispatch / ScopeValidation. Compilation now threads an internalFunctions table through compileStmtList, compileExprWithInternals, constructor/fallback/receive paths, ADT storage writes, and event emission so compileInternalCallArgs can resolve the callee and expand args (direct Expr.param forwarding for expanded types, plus a legacy expanded-arg list path with checked dynamic-member projections).

Validation replaces raw Yul arg-count checks with validateInternalCallSourceArgs: logical arity, exact type/layout match for forwarded params, and constructor bodies now validate internal calls with caller params. Feature tests and Yul smoke specs cover fallback, ADT ctor payloads, and composite permit + bytes shapes.

Proof modules are updated for the new compile signatures and empty internal-fn tables on supported fragments.

Reviewed by Cursor Bugbot for commit 70d116e. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
verity Ready Ready Preview, Comment Jun 16, 2026 11:06am

Request Review

Comment thread Compiler/CompilationModel/Dispatch.lean
@Th0rgal Th0rgal changed the base branch from task/1975-struct-array-calldata to main June 14, 2026 20:45
Comment thread Compiler/CompilationModel/Compile.lean

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 70d116e. Configure here.

if isDynamicParamType ty then [s!"{name}_data_offset"] else staticParamBindingNames name ty
| ty@(ParamType.tuple _) =>
if isDynamicParamType ty then [s!"{name}_data_offset"] else staticParamBindingNames name ty
| ParamType.newtypeOf _ baseTy => internalCallYulArgNamesForBase name baseTy

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arg name mismatch for newtypeOf wrapping dynamic types

High Severity

internalCallYulArgNamesForBase handles newtypeOf _ baseTy by recursing into baseTy, but internalFunctionYulParamNames checks isDynamicParamType param.ty at the newtypeOf level and returns only ["{name}_data_offset"] for dynamic base types. For newtypeOf _ bytes (or string/array), the callee definition gets 1 Yul parameter via internalFunctionYulParamNames, but the caller generates 2 Yul arguments via internalCallYulArgNamesForBase (which recurses to bytes[data_offset, length]). This arity mismatch would cause a Yul compilation error for any internal call forwarding a newtypeOf-wrapped dynamic type.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 70d116e. Configure here.


def directForwardedInternalCallArgName? : Expr → Option String
| Expr.param name => some name
| _ => none

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated helper function across two files

Low Severity

directForwardedInternalCallArgName? in ExpressionCompile.lean and directForwardedInternalArgName? in ValidationCalls.lean are identical functions both newly added in this PR. Both match Expr.param name to some name and everything else to none. One shared definition (e.g., in InternalArgs.lean) would avoid the duplication risk of future divergence.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 70d116e. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor
\n### CI Failure Hints\n\nFailed jobs: `compiler-regressions`\n\nCopy-paste local triage:\n```bash\nmake check\nlake build\nFOUNDRY_PROFILE=difftest forge test -vv\n```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proof follow-up: dynamic/composite internal-helper argument lowering

1 participant